#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>

/**
 *时间复杂度：O(mn)
 空间复杂度：O(1)
 * 反转矩阵
 * @return
 */
int main() {

	int arr[110][110]{};

	int m, n;
	scanf("%d %d", &m, &n);

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &arr[i][j]);
		}
	}

	int op;
	scanf("%d", &op);

	if (op == 1) {
		for (int i = 0; i < m; i++) {
			int leftIdx = 0;
			int rightIdx = n - 1;
			while (leftIdx < rightIdx) {
				std::swap(arr[i][leftIdx], arr[i][rightIdx]);
				leftIdx++;
				rightIdx--;
			}
		}
	}
	else {
		for (int i = 0; i < n; i++) {
			int topIdx = 0;
			int bottomIdx = m - 1;
			while (topIdx < bottomIdx) {
				std::swap(arr[topIdx][i], arr[bottomIdx][i]);
				topIdx++;
				bottomIdx--;
			}
		}
	}

	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			printf("%d ", arr[i][j]);
		}
		printf("\n");
	}


	return 0;
}